{% if errors %}
<div class="alert alert-danger py-2 mb-3">
  <ul class="mb-0">
    {% for e in errors %}<li>{{ e }}</li>{% endfor %}
  </ul>
</div>
{% endif %}

<div class="row">
  <div class="col-md-6">
    <div class="mb-3">
      <label for="name" class="form-label">耗材名称 *</label>
      <input type="text" class="form-control" id="name" name="name" value="{{ name|default:consumable.name|default:'' }}" required>
    </div>
  </div>
  <div class="col-md-6">
    <div class="mb-3">
      <label for="code" class="form-label">耗材编码 *</label>
      <input type="text" class="form-control" id="code" name="code" value="{{ code|default:consumable.code|default:'' }}" required>
    </div>
  </div>
</div>

<div class="row">
  <div class="col-md-6">
    <div class="mb-3">
      <label for="category" class="form-label">耗材类别 *</label>
      <select class="form-select" id="category" name="category" required>
        <option value="">请选择耗材类别</option>
        {% for category in categories %}
        <option value="{{ category.id }}" {% if (consumable and consumable.category_id == category.id) or category_id|add:'0' == category.id %}selected{% endif %}>{{ category.name }}</option>
        {% endfor %}
      </select>
    </div>
  </div>
  <div class="col-md-6">
    <div class="mb-3">
      <label for="warehouse" class="form-label">所属仓库 *</label>
      <select class="form-select" id="warehouse" name="warehouse" required>
        <option value="">请选择仓库</option>
        {% for warehouse in warehouses %}
        <option value="{{ warehouse.id }}" {% if (consumable and consumable.warehouse_id == warehouse.id) or warehouse_id|add:'0' == warehouse.id %}selected{% endif %}>{{ warehouse.name }}</option>
        {% endfor %}
      </select>
    </div>
  </div>
</div>

<div class="row">
  <div class="col-md-6">
    <div class="mb-3">
      <label for="unit" class="form-label">单位 *</label>
      <input type="text" class="form-control" id="unit" name="unit" value="{{ unit|default:consumable.unit|default:'' }}" required>
    </div>
  </div>
  <div class="col-md-6">
    <div class="mb-3">
      <label for="quantity" class="form-label">数量 *</label>
      <input type="number" class="form-control" id="quantity" name="quantity" step="0.01" value="{{ quantity|default:consumable.quantity|default:'' }}" required>
    </div>
  </div>
</div>

<div class="row">
  <div class="col-md-6">
    <div class="mb-3">
      <label for="min_quantity" class="form-label">最低库存</label>
      <input type="number" class="form-control" id="min_quantity" name="min_quantity" step="0.01" value="{{ min_quantity|default:consumable.min_quantity|default:'' }}">
    </div>
  </div>
  <div class="col-md-6">
    <div class="mb-3">
      <label for="purchase_price" class="form-label">采购单价</label>
      <input type="number" class="form-control" id="purchase_price" name="purchase_price" step="0.01" value="{{ purchase_price|default:consumable.purchase_price|default:'' }}">
    </div>
  </div>
</div>

<div class="row">
  <div class="col-md-6">
    <div class="mb-3">
      <label for="supplier" class="form-label">供应商</label>
      <select class="form-select" id="supplier" name="supplier">
        <option value="">请选择供应商</option>
        {% for supplier in suppliers %}
        <option value="{{ supplier.id }}" {% if (consumable and consumable.supplier_id == supplier.id) or supplier_id|add:'0' == supplier.id %}selected{% endif %}>{{ supplier.name }}</option>
        {% endfor %}
      </select>
    </div>
  </div>
</div>

<div class="mb-3">
  <label for="description" class="form-label">描述</label>
  <textarea class="form-control" id="description" name="description" rows="3">{{ description|default:consumable.description|default:'' }}</textarea>
</div>
